<?php

namespace App\Library\Logic;

use App\Library\Requests\Base\BasePageRequest;
use App\Models\AuctionBidModel;

class AuctionBidLogic extends AuctionBidModel
{
    /**
     * 参拍记录
     * @param BasePageRequest $request
     * @return array
     *
     */
    public static function bidRecord(BasePageRequest $request): array
    {
        $builder = self::query()->where('user_id', USERID)
            ->leftJoin('auction', 'auction.id', 'auction_bid.auction_id')
            ->groupBy('auction_bid.auction_id')
            ->select([
                'auction.serial_number',
                'auction.title',
                'auction.file_id',
                'auction.is_end',
                'auction.end_at',
                'auction.start_price',
                'auction.tag',
                'auction_bid.user_id',
                'auction_bid.auction_id',
                'auction_bid.created_at',
                'current_price',
            ]);
        return paginate(helpBuilder($builder, $request)->orderByDesc('auction_bid.created_at')->paginate($request->post('limit')));
    }

    public static function userCount(int $auctionId): int
    {
        return self::query()->where('auction_id', $auctionId)->groupBy('user_id')->count();
    }
}
